from flask import Flask

from app.config import APSchedulerConfig
from app.globals import env
from app.init import FlaskInit

__version__ = '21.0402.1138'


def create_app():
    print(f' * App Version: {__version__}')
    app = Flask(__name__)
    app.config['DEBUG'] = env.cfg.get('APP_DEBUG')
    app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
    app.config['SECRET_KEY'] = r'\xff\x9a\x00\x03\xf1\xf2\x06\x9f\x95\xdfNn\xb9\xcde' \
                               r'\xa0a<Z\x89?\xba\x80\x809\x8c\x90\xc2\xc79\xd5\x17'
    app.config['SWAGGER'] = {
        'title': 'shotgun',
        'doc_dir': './docs/swagger',
        'openapi': '3.0.2'
    }

    app.config.from_object(APSchedulerConfig())
    FlaskInit(app)

    from app.mod_trade.api.account import bp_account
    from app.mod_trade.api.trade import bp_trade

    app.register_blueprint(bp_trade, url_prefix='/api')
    app.register_blueprint(bp_account, url_prefix='/api')
    return app
